<template>
  <div class="mainBox">
    <div class="header jusCenter">
      <div class="card aliCenter">
        <div class="Avatar">
          <el-avatar :size="330" :src="userInfo.head" />
        </div>
        <div class="nameBox">
          <div class="titleName">{{ userInfo.name }}</div>
          <div class="nameAndPhone aliCenter">
            <div class="name">{{ userInfo.name }}</div>
            <div class="phone">{{ userInfo.phone }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="list">
      <div class="listBox center">
        <div class="card">
          <div class="cardTop title aliCenter">
            <div>Customer Information</div>
            <div></div>
          </div>
          <div class="cardContent">
            <el-row>
              <el-col :span="12" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">First Name:</div>
                  <el-input style="flex: 3" class="inpute" v-model="formDataAdd.ownerFirstName" />
                </div>
              </el-col>
              <el-col :span="12" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Last Name:</div>
                  <el-input style="flex: 3" class="inpute" v-model="formDataAdd.ownerLastName" />
                </div>
              </el-col>
              <el-col :span="12" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Phone Number:</div>
                  <el-input style="flex: 3" class="inpute" v-model="formDataAdd.ownerPhone" />
                </div>
              </el-col>
              <el-col :span="12" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Email Number:</div>
                  <el-input style="flex: 3" class="inpute" v-model="formDataAdd.ownerEmail" />
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
      <div class="listBox center">
        <div class="card">
          <div class="cardTop title aliCenter">
            <div>Vehicle Information</div>
            <div></div>
          </div>
          <div class="cardContent">
            <el-row>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Brand and Model:</div>
                  <el-cascader
                    placeholder=" "
                    style="flex: 5"
                    v-model="formDataAdd.carName"
                    :options="optionsCar"
                  />
                </div>
              </el-col>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">License Plate Number:</div>
                  <el-input style="flex: 4" class="inpute" v-model="formDataAdd.carNo" />
                  <div class="PictureRecognition center" @click="PictureRecognitionFn(0)">
                    Upload lmage
                  </div>
                </div>
              </el-col>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Chassis Number (VIN):</div>
                  <el-input style="flex: 6" class="inpute" v-model="formDataAdd.carVIN" />
                  <div class="PictureRecognition center" @click="PictureRecognitionFn(1)">
                    Upload lmage
                  </div>
                </div>
              </el-col>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Installation Part:</div>
                  <el-select
                    size="large"
                    v-model="formDataAdd.carApart"
                    placeholder=""
                    style="flex: 7"
                  >
                    <el-option
                      v-for="item in optionsCard"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
      <!-- <div class="listBox center">
        <div class="card">
          <div class="cardTop title aliCenter">
            <div>Store Information</div>
            <div></div>
          </div>
          <div class="cardContent">
            <el-row>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Store Name:</div>
                  <el-input
                    disabled
                    style="flex: 7"
                    class="inpute"
                    v-model="formDataAdd.storeWorkName"
                  />
                </div>
              </el-col>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Store Address:</div>
                  <el-input disabled style="flex: 7" class="inpute" v-model="formDataAdd.region" />
                </div>
              </el-col>
              <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Store Phone Number:</div>
                  <el-input
                    disabled
                    style="flex: 5"
                    class="inpute"
                    v-model="formDataAdd.storeWorkPhone"
                  />
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
      </div> -->
      <div v-for="(item, index) in squailtyData" :key="index">
        <div class="listBox center">
          <div class="card">
            <div class="cardTop title aliCenter" style="justify-content: space-between">
              <div>Warranty Information</div>
              <div class="addButton center" v-if="index == 0" @click="AddQualityFn">Add</div>
            </div>
            <div class="cardContent">
              <el-row>
                <el-col :span="24" class="col size2">
                  <div class="colBox">
                    <div style="flex: 1">Warranty Serial Number:</div>
                    <el-input
                      @blur="filmChangeFn(item)"
                      style="flex: 4"
                      class="inpute"
                      v-model="item.filmNo"
                    />
                    <div class="PictureRecognition center" @click="PictureRecognitionFn(2, item)">
                      Upload lmage
                    </div>
                  </div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div class="colBox">
                    <div style="flex: 1">Warranty Period:</div>
                    <el-input style="flex: 6" class="inpute" v-model="item.filmAge" />
                  </div>
                </el-col>
                <!-- <el-col :span="24" class="col size2">
                <div class="colBox">
                  <div style="flex: 1">Product Batch Number:</div>
                  <el-input style="flex: 4" class="inpute" v-model="formDataAdd.SerialNumber" />
                  <div class="PictureRecognition center" @click="PictureRecognitionFn(3)">
                    Upload lmage
                  </div>
                </div>
              </el-col> -->
                <el-col :span="24" class="col size2">
                  <div class="colBox">
                    <div style="flex: 1">Product Type:</div>

                    <el-select size="large" v-model="item.filmType" placeholder="" style="flex: 7">
                      <el-option
                        v-for="item in optionsFilmType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div class="colBox">
                    <div style="flex: 1">Product Model:</div>
                    <el-input style="flex: 7" class="inpute" v-model="item.filmName" />
                  </div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div class="colBox">
                    <div style="flex: 1">Remarks:</div>
                    <el-input style="flex: 17" class="inpute" v-model="item.remark" />
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <div class="listBox center">
          <div class="card">
            <div class="cardTop title aliCenter">
              <div>Please upload corresponding photos</div>
              <div></div>
            </div>
            <div class="cardContent upImage">
              <el-row>
                <el-col
                  :span="6"
                  class="col size2"
                  v-for="(item2, index2) in imageList[index]"
                  :key="index2"
                >
                  <div>
                    <div class="jusCenter">
                      <div
                        class="upImg center"
                        v-show="!item2.image"
                        @click="upImgFnBox(item2, index2, index)"
                      >
                        <el-upload
                          class="avatar-uploader"
                          :action="baseURL + 'api/uploadAvatar'"
                          :show-file-list="false"
                          :on-success="handleAvatarSuccess"
                          :before-upload="beforeAvatarUpload"
                        >
                          <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
                        </el-upload>
                      </div>
                      <!-- <div
                        class="upBOx"
                        @click="upImgFn(item2, index2, index)"
                        v-show="!item2.image"
                      >
                        <div class="upImg center">+</div>
                        <input
                          ref="inputFile"
                          type="file"
                          style="display: none"
                          @change="handleFileUpload"
                        />
                      </div> -->
                      <div v-show="item2.image" class="imgBox">
                        <img :src="item2.image" alt="" />
                        <div class="Mask center">
                          <div @click="magnifyFn(item2)">
                            <el-icon color="white"><Search /></el-icon>
                          </div>
                          <div @click="deleteImgFn(item2)">
                            <el-icon color="red"><Delete /></el-icon>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="imgFootText">{{ item2.title }}</div>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
      </div>
      <div class="listBox center">
        <div class="card">
          <div class="cardTop title aliCenter">
            <div>Tips</div>
            <div></div>
          </div>
          <div class="cardContent">
            <div class="size">
              1. Wei helps customers navigate to your store, please fill in the address as soonas
              possible <br />
              2.Wei helps customers navigate to your store, please fill in the address as soonas
              possible
            </div>
          </div>
        </div>
      </div>
      <div class="footButtonS">
        <div class="footButton center size" @click="ReturnFn">Return</div>
        <div class="footButton center size" @click="ConfirmFn">Confirm</div>
      </div>
    </div>
    <input ref="inputFile2" type="file" style="display: none" />
    <input ref="inputFile3" type="file" style="display: none" />
    <input ref="inputFile4" type="file" style="display: none" />
    <input ref="inputFile5" type="file" style="display: none" />
    <el-dialog v-model="dialogVisibleImage" width="500">
      <div class="imageBox">
        <img :src="dialogVisibleImageUrl" alt="" srcset="" />
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { carList } from '@/http/api/car.js'
import { uploadAvatar, qualityListAddSmall, qualityListAddSmall2, qualitNumberDetils, recognitionimg, qualitDetils, qualitChange, recognitionImgQualit2 } from '@/http/api/my.js'
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
import { baseURL } from '@/http/request.js'
const router = useRouter()
const route = useRoute()
let userInfo = reactive(JSON.parse(localStorage.getItem('storeInfo')))

let formData = reactive({})
let formDataAdd = reactive({})
let upImg = ref(false)
let inputFile = ref(null)
let upNumber = 0
let optionsCard = ref([
  {
    label: 'complete vehicle',
    value: '整车'
  },
  {
    label: 'windshield',
    value: '前挡'
  },
  {
    label: 'Side gear',
    value: '侧挡'
  },
  {
    label: 'roof',
    value: '车顶'
  },
  {
    label: 'front bumper',
    value: '前杠'
  },
  {
    label: 'rear bumper',
    value: '后杠'
  },
  {
    label: 'hood',
    value: '机盖'
  }, {
    label: 'front fender',
    value: '前叶子板'
  }, {
    label: 'Rear Leaf Board',
    value: '后叶子板'
  }, {
    label: 'car door',
    value: '车门'
  }, {
    label: 'side skirt',
    value: '侧裙'
  }, {
    label: 'back cover',
    value: '后盖'
  },
])
let optionsFilmType = ref([
  {
    label: 'TPU PPF',
    value: '漆面膜'
  },
  {
    label: 'COLOR PPF',
    value: '改色膜'
  },
  {
    label: 'WINDOW TINT',
    value: '车顶膜'
  },
  {
    label: 'SUNROOF FILM',
    value: '太阳膜'
  },
])
let optionsCar = ref([])
const gerCarList = async () => {
  let res = await carList({
    size: 10000,
    page: 1
  })
  optionsCar.value = res.res.map((item) => {
    item.label = item.carModel
    item.value = item.carModel
    item.children = []
    item.carName.split('/').forEach((item2) => {
      item.children.push({
        label: item2,
        value: item2
      })
    })
    return item
  })
}
let index1 = 0
let index2 = 0
let num2 = 0
const handleAvatarSuccess = async (dataImg) => {
  console.log(index1, index2)
  let resIMg = await recognitionImgQualit2({ url: dataImg.image_url })
  upImgData.image = dataImg.image_url
  let textData = JSON.parse(resIMg.res).words_result.map(item => {
    return item.words
  }).join('')

  if (imageList[index1]) {
    if (index1 == 0) {
      if (index2 == 0) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 1) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 3) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 2) {
        imageList.value[index1][index2].textData = textData
      }
    } else {
      if (index2 == 0) {
        imageList.value[index1][index2].textData = textData
      }
    }
  } else {
    if (index2 == 0) {
      imageList.value[index1][index2].textData = textData
    } else if (index2 == 1) {
      imageList.value[index1][index2].textData = textData
    } else if (index2 == 3) {
      imageList.value[index1][index2].textData = textData
    } else if (index2 == 2) {
      imageList.value[index1][index2].textData = textData
    }
  }
  console.log(index1)
  if (index1 == 0) {
    if (index2 == 1) {
      if (textData.indexOf(formDataAdd.carNo) == -1) {
        num2++
        ElMessage.error('The information in the license plate image does not match the details provided.')
      } else {
        ElMessage.success('Picture comparison successful')
        // carNo = true
      }
    } else if (index2 == 3) {
      if (formDataAdd.carVIN) {
        if (textData.indexOf(formDataAdd.carVIN) == -1) {
          num2++
          ElMessage.error('The information in the frame number image does not match the input.')
        } else {
          ElMessage.success('Picture comparison successful')
          // carVINNo = true
        }
      } else {
        ElMessage.error('Please provide the vehicle identification number.')
      }

    } else if (index2 == 2) {
      console.log(squailtyData.value[index1])
      if (squailtyData.value[index1].filmNo) {
        if (textData.indexOf(squailtyData.value[index1]
          .filmNo) == -1) {
          num2++
          ElMessage.error('The batch number image information does not match the input.')
        } else {
          ElMessage.success('Picture comparison successful')
          // formDataAddQuality[index1].filmNoIS = true
          // console.log(formDataAddQuality);
        }
      } else {
        ElMessage.error('Please provide the batch number.')
      }

    } else if (index2 == 0) {
      ElMessage.success('Upload of image successful')
    }

  } else {
    if (index2 == 0) {
      console.log(squailtyData)
      if (textData.indexOf(squailtyData.value[index1]
        .filmNo) == -1) {
        num2++
        ElMessage.error('The batch number image information does not match the input.')
      } else {
        ElMessage.success('Picture comparison successful')
      }
    }
  }

}
let upImgData = ''
const upImgFnBox = (data, index2Data, index) => {
  index1 = index
  index2 = index2Data
  upImgData = data
}
const upImgFn = (data, index2Data, index) => {
  console.log(inputFile.value)
  console.log(index2Data, index)
  inputFile.value[index2Data].addEventListener('change', async function (event) {
    index1 = index
    index2 = index2Data
    var files = event.target.files[0]
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const res = await uploadAvatar(formData)
    let resIMg = await recognitionImgQualit2({ url: res.image_url })
    data.image = res.image_url
    let textData = JSON.parse(resIMg.res).words_result.map(item => {
      return item.words
    }).join('')

    let dataList = {
      textData,
      title: ''
    }
    if (imageList[index1]) {
      if (index1 == 0) {
        if (index2 == 0) {
          imageList.value[index1][index2].textData = textData
        } else if (index2 == 1) {
          imageList.value[index1][index2].textData = textData
        } else if (index2 == 3) {
          imageList.value[index1][index2].textData = textData
        } else if (index2 == 2) {
          imageList.value[index1][index2].textData = textData
        }
      } else {
        if (index2 == 0) {
          imageList.value[index1][index2].textData = textData
        }
      }
    } else {
      if (index2 == 0) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 1) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 3) {
        imageList.value[index1][index2].textData = textData
      } else if (index2 == 2) {
        imageList.value[index1][index2].textData = textData
      }
    }
    console.log(index1)
    if (index1 == 0) {
      if (index2 == 1) {
        if (textData.indexOf(formDataAdd.carNo) == -1) {
          num2++
          ElMessage.error('The information in the license plate image does not match the details provided.')
        } else {
          ElMessage.success('Picture comparison successful')
          // carNo = true
        }
      } else if (index2 == 3) {
        if (formDataAdd.carVIN) {
          if (textData.indexOf(formDataAdd.carVIN) == -1) {
            num2++
            ElMessage.error('The information in the frame number image does not match the input.')
          } else {
            ElMessage.success('Picture comparison successful')
            // carVINNo = true
          }
        } else {
          ElMessage.error('Please provide the vehicle identification number.')
        }

      } else if (index2 == 2) {
        console.log(squailtyData.value[index1])
        if (squailtyData.value[index1].filmNo) {
          if (textData.indexOf(squailtyData.value[index1]
            .filmNo) == -1) {
            num2++
            ElMessage.error('The batch number image information does not match the input.')
          } else {
            ElMessage.success('Picture comparison successful')
            // formDataAddQuality[index1].filmNoIS = true
            // console.log(formDataAddQuality);
          }
        } else {
          ElMessage.error('Please provide the batch number.')
        }

      } else if (index2 == 0) {
        ElMessage.success('Upload of image successful')
      }

    } else {
      if (index2 == 0) {
        if (textData.indexOf(squailtyData[index1]
          .filmNo) == -1) {
          num2++
          ElMessage.error('The batch number image information does not match the input.')
        } else {
          ElMessage.success('Picture comparison successful')
        }
      }
    }

  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile.value[index2Data].click()
}
const filmChangeFn = async (item) => {
  let data = {
    filmNo: item.filmNo ? item.filmNo : qualityNo.filmNo,
    storeId: JSON.parse(localStorage.getItem('storeInfo')).id
  }
  const res = await qualitNumberDetils(data)
  console.log(res)
  if (res.res.unUseCount != 0) {
    if (item) {
      item.filmType = res.res.filmType
      item.filmName = res.res.filmName
      item.filmAge = res.res.filmAge
      item.SerialNumber = res.res.SerialNumber
    } else {
      qualityNo.filmType = res.res.filmType
      qualityNo.filmName = res.res.filmName
      qualityNo.filmAge = res.res.filmAge
      qualityNo.SerialNumber = res.res.SerialNumber
    }
  } else {
    ElMessage.error('The numbering and frequency have ceased.')
  }


}
let num = ref(0)
const ConfirmFn = async () => {
  let updata = formDataAdd
  try {
    squailtyData.value.forEach((item2, index2) => {
      imageList.value[index2].forEach((item) => {
        console.log(item)
        if (!item.image) {
          throw 'Please add the picture.'
        }
      })
    })
    updata.qualityList = squailtyData.value
    updata.imagesList = JSON.stringify(imageList.value)
    let res = ''
    if (num2 < 5 && upNumber <= 3) {
      imageList.value.forEach((item, index) => {
        item.forEach((item2, index2) => {
          if (index == 0) {
            if (item2.title == 'Construction vehicles') {
              if (item2.textData.indexOf(formDataAdd.carNo) == -1) {
                upNumber++
                throw 'The information in the license plate image does not match the details provided.'
              }
            } else if (item2.title == 'Vehicle nameplate') {
              if (item2.textData.indexOf(formDataAdd.carVIN) == -1) {
                upNumber++
                throw 'The information in the frame number image does not match the input.'
              }
            } else if (item2.title == 'Film roll number/warranty number') {
              if (item2.textData.indexOf(squailtyData.value[index1]
                .filmNo) == -1) {
                upNumber++
                throw 'The batch number image information does not match the input.'
              }
            }
          } else {
            if (item2.title == '批次号') {
              if (item2.title == '批次号') {
                if (item2.textData.indexOf(squailtyData.value[index1]
                  .filmNo) == -1) {
                  upNumber++
                  throw 'The batch number image information does not match the input.'
                }
              }
            }
          }
        })
      })
      try {
        res = await qualityListAddSmall(updata)
        ElMessage.success(res.message)
        res.type == 0 ? upNumber.value++ : setTimeout(() => {
          router.push('/storeMy')
        }, 1000)
      } catch (error) {
        ElMessage.error(error)
      }
    } else {
      try {
        squailtyData.value.forEach(async (item2, index2) => {
          let upData2 = {
            ...item2,
            ...formDataAdd,
            imagesList: JSON.stringify(imageList.value[index2])

          }
          res = await qualityListAddSmall2(upData2)
          ElMessage.success('successfully upload')
        })
      } catch (error) {
        ElMessage.error('fail to add')
      }

      setTimeout(() => {
        router.push('/storeMy')
      }, 1000)
    }
  } catch (error) {
    console.log(error)
    ElMessage.error(error)
  }
}
const ReturnFn = () => {
  router.go(-1)
  Object.assign(formDataAdd, {})
}
// const getData = () => {
//   formDataAdd.storeWorkName = userInfo.name
//   formDataAdd.storeWork = userInfo.id
//   formDataAdd.storeWorkPhone = userInfo.phone
//   formDataAdd.region = JSON.parse(userInfo.region).join(',')
// }
let inputFile2 = ref(null)
let inputFile3 = ref(null)
let inputFile4 = ref(null)
let inputFile5 = ref(null)
const upImgFn2 = () => {
  let res = ''
  inputFile2.value.addEventListener('change', async function (event) {
    var files = event.target.files[0]
    console.log(files)
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const url = await uploadAvatar(formData)
    res = await recognitionimg({
      url: url.image_url
    })
    let words = JSON.parse(res.res)
    let regex =
      /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$/
    words.words_result.forEach((item, index) => {
      if (regex.test(item.words)) {
        formDataAdd.carNo = item.words
        ElMessage.success('Identification successful')
      }
    })
  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile2.value.click()
}
const upImgFn3 = () => {
  let res = ''
  inputFile3.value.addEventListener('change', async function (event) {
    var files = event.target.files[0]
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const url = await uploadAvatar(formData)
    res = await recognitionimg({
      url: url.image_url
    })
    let words = JSON.parse(res.res)
    let carVIN = ''
    const vinRegex = /[A-Za-z]{2}[A-Za-z0-9]{15}/g
    words.words_result.forEach((item) => {
      if (item.words.match(vinRegex)) {
        carVIN = item.words.match(vinRegex)[0]
      }
    })


    if (carVIN.split('').length == 17) {
      formDataAdd.carVIN = carVIN
      ElMessage.success('Identification successful')
    } else {
      ElMessage.error('Identification failure')
    }

  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile3.value.click()
}
const upImgFn4 = () => {
  let res = ''
  inputFile4.value.addEventListener('change', async function (event) {
    var files = event.target.files[0]
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const url = await uploadAvatar(formData)
    res = await recognitionimg({
      url: url.image_url
    })
    let words = JSON.parse(res.res)
    let carVIN = ''
    const vinRegex = /[A-Za-z0-9]{12}[A-Za-z0-9-]{2}[A-Za-z0-9-]{4}/g
    words.words_result.forEach((item) => {
      if (item.words.match(vinRegex)) {
        carVIN = item.words.match(vinRegex)[0]
      }
    })
    if (carVIN.split('').length > 14) {
      qualityNo.filmNo = carVIN
      ElMessage.success('Identification successful')
      filmChangeFn(qualityNo)
    } else {
      ElMessage.error('Identification failure')
    }

  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile4.value.click()
}
const upImgFn5 = () => {
  let res = ''
  inputFile5.value.addEventListener('change', async function (event) {
    var files = event.target.files[0]
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const url = await uploadAvatar(formData)
    res = await recognitionimg({
      url: url.image_url
    })
    let words = JSON.parse(res.res)
    let carVIN = ''
    const vinRegex = /[A-Za-z0-9]{10}[A-Za-z0-9-]{4}/g
    words.words_result.forEach((item) => {
      if (item.words.match(vinRegex)) {
        carVIN = item.words.match(vinRegex)[0]
      }
    })
    if (carVIN.split('').length == 14) {
      formDataAdd.SerialNumber = carVIN
      ElMessage.success('Identification successful')
    } else {
      ElMessage.error('Identification failure')
    }

  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile5.value.click()
}
let qualityNo = {}
const PictureRecognitionFn = (num, item) => {
  if (num == 0) {
    upImgFn2()
  } else if (num == 1) {
    upImgFn3()
  } else if (num == 2) {
    upImgFn4()
    qualityNo = item
  } else if (num == 3) {
    upImgFn5()
  }
}
// 未完
const getChangeData = async () => {
  if (route.query.id) {
    let res = await qualitDetils({ id: route.query.id })
    res.res.carName = JSON.parse(res.res.carName)
    let imageListData = JSON.parse(res.res.imgList)
    imageList.value.forEach((item) => {
      imageListData.forEach((item2) => {
        if (item.title == item2.title) {
          item.image = item2.image
        }
      })
    })
    Object.assign(formDataAdd, res.res)
    squailtyData.value[0].filmAge = res.res.filmAge
    squailtyData.value[0].filmType = res.res.filmType
    squailtyData.value[0].filmName = res.res.filmName
    squailtyData.value[0].remark = res.res.remark
    squailtyData.value[0].filmNo = res.res.filmNo
    formDataAdd.storeWorkName = res.res.storeWorkName
    formDataAdd.storeWork = res.res.storeWork
    formDataAdd.storeWorkPhone = res.res.storeWorkPhone
    formDataAdd.region = res.res.region
  }
}
const deleteImgFn = (data) => {
  data.image = ''
  data.upImg = false
}
let dialogVisibleImage = ref(false)
let dialogVisibleImageUrl = ref('')
const magnifyFn = (data) => {
  dialogVisibleImage.value = true
  dialogVisibleImageUrl.value = data.image
}
let squailtyData = ref([
  {
    filmAge: '',
    filmName: '',
    filmType: '',
    remark: '',
  }
])
let imageList = ref([
  [{
    title: 'Vehicles with doors',
    image: '',
    upImg: false
  }, {
    title: 'Construction vehicles',
    image: '',
    upImg: false
  }, {
    title: 'Film roll number/warranty number',
    image: '',
    upImg: false
  }, {
    title: 'Vehicle nameplate',
    image: '',
    upImg: false
  }]
])

const AddQualityFn = () => {
  squailtyData.value.push({})
  imageList.value.push([{
    title: 'Film roll number/warranty number',
    image: '',
    upImg: false
  }])
}
onMounted(() => {
  // getData()
  gerCarList()
  getChangeData()
  window.scrollTo({
    top: 200, // 垂直滚动到 500 像素的位置
    left: 0,  // 水平滚动到 0 像素的位置
    behavior: 'auto' // 平滑滚动
  })
})
</script>

<style lang="scss" scoped>
.PictureRecognition {
  margin-left: 10px;
  width: 190px;
  height: 37px;
  background: #ffdd00;
  border-radius: 10px;
  font-size: 20px;
  font-weight: bold;
  color: black;
  cursor: pointer;
}
.PictureRecognition:active {
  background: black;
  color: white;
}
.mainBox {
  min-height: 100vh;
  background: #000000;
  padding: 50px 0;
}
.topCard {
  width: 100%;
  position: relative;
  .card {
    width: 1850px;
    height: 450px;
    border-radius: 50px;
    overflow: hidden;
    position: relative;

    .cardBak {
      width: 1850px;
      height: 450px;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 1;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.listBox {
  width: 100%;
  margin-top: 45px;
  cursor: pointer;
  .card {
    width: 1800px;
    border-radius: 20px;
    overflow: hidden;
    background: #1a1c1d;
    .cardTop {
      height: 100px;
      width: 100%;
      background: #ffdd00;
      margin: 0 0 10px 0;
      padding: 0 20px;
      font-weight: bold;
      color: black;
    }
    .cardContent {
      padding: 20px;
      font-size: 24px;
      color: white;
    }
  }
}
::v-deep .el-input__inner {
  color: #ffdd00;
}
.upImage {
  height: 500px;
}
.cardCenter {
  padding: 20px;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}
.cardCenterTop {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  .size {
    color: #ffdd00;
    font-size: 50px;
    font-weight: bold;
  }
}
.cardCenterCenter {
  width: 100%;
  text-align: center;
  font-size: 50px;
  margin-top: 30px;
}
.cardCenterFoot {
  display: flex;
  justify-content: space-between;
  font-size: 25px;
  color: #ffdd00;
  margin-top: 20px;
}
.uploadImage {
  width: 400px;
  height: 400px;
  img {
    width: 100%;
    height: 100%;
  }
}
.listBotton {
  width: 100%;
  .botton {
    width: 170px;
    height: 70px;
    background: #ffdd00;
    font-weight: bold;
    font-size: 18px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;

    color: black;
    margin-top: 20px;
  }
  .botton:active {
    background: black;
    color: white;
  }
}
.AddVehiclenCard {
  width: 1800px;
  height: 400px;
  border-radius: 20px;
  overflow: hidden;
  background: #1a1c1d;
  .AddVehiclenCardTop {
    height: 100px;
    width: 100%;
    background: #ffdd00;
    font-size: 24px;
    padding: 0 20px;
    font-weight: bold;
    color: black;
  }
}
.AddVehiclenCardContent {
  padding: 10px;
  .left {
    margin-right: 30px;
    margin-left: 50px;
  }
}
.upImg {
  background: #3c3c3c;
  width: 260px;
  height: 260px;
  border-radius: 20px;
  font-size: 50px;
  cursor: pointer;
}

.imgBox {
  width: 260px;
  height: 260px;
  border-radius: 20px;
  position: relative;
  left: 0;
  top: 0;
  img {
    width: 100%;
    height: 100%;
  }
  .Mask {
    background: black;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    justify-content: space-around;
    font-size: 30px;
  }
  .Mask:hover {
    opacity: 0.6;
  }
  cursor: pointer;
}
::v-deep .el-dialog {
  padding: 0;
  border-radius: 20px;
  width: 1800px;
}
::v-deep .el-dialog__header {
  padding: 0;
}
.bakImg {
  width: 800px;
  height: 800px;
  img {
    width: 100%;
    height: 100%;
  }
}
::v-deep .el-dialog__body2 {
  width: 800px !important;
}
::v-deep .el-form-item__label {
  font-size: 30px;
  color: white;
}
::v-deep .el-radio__input.is-checked .el-radio__inner {
  background: #ffdd00;
  border: #ffdd00;
}
::v-deep .el-radio__input .is-checked {
  color: white !important;
  font-size: 24px;
}
.col {
  width: 100%;
}
::v-deep .el-radio__label {
  color: white !important;
  font-size: 24px;
}
::v-deep .el-input {
  height: 40px;
}
::v-deep .el-input__wrapper {
  background: #242424 !important;
  border: 1px solid rgb(255, 221, 0);
  box-shadow: 0 0 !important;
}
::v-deep .el-select__wrapper {
  background: #242424 !important;
  border: 1px solid rgb(255, 221, 0);
  box-shadow: 0 0 !important;
}
::v-deep .el-select__selected-item {
  color: #ffdd00;
}
.inpute1 {
  width: 500px;
}

.cofimButton {
  width: 220px;
  height: 70px;
  background: #ffdd00;
  border-radius: 20px;
  font-size: 30px;
  font-weight: bold;
  color: black;
  cursor: pointer;
}
.cofimButton:active {
  background: black;
  color: white;
}

.header {
  .card {
    background: #1c2123;
    border-radius: 20px;
    width: 1800px;
    height: 450px;
    padding: 0 20px;
    margin-top: 80px;
  }
  .nameBox {
    margin-left: 80px;
    .titleName {
      width: 1000px;
      font-size: 60px;
      color: #ffdd00;
      font-weight: bold;
      white-space: pre-wrap; /* 保留空白符序列，但是当到达容器边界时进行换行 */
      overflow-wrap: break-word; /* 在长单词或URL地址内部进行换行 */
      word-break: break-all; /* 允许在任意字符间断开（用于CJK文字等） */
    }
    .nameAndPhone {
      margin-top: 50px;
      .name {
        font-size: 35px;
        color: #ffdd00;
      }
      .phone {
        font-size: 35px;
        color: #ffdd00;
        margin-left: 50px;
      }
    }
  }
}
::v-deep .el-input__wrapper {
  background: #242424 !important;
  border: 1px solid rgb(255, 221, 0);
  box-shadow: 0 0 !important;
}
.imgFootText {
  text-align: center;
}
.upImg {
  background: #3c3c3c;
  width: 260px;
  height: 260px;
  border-radius: 20px;
  font-size: 50px;
  cursor: pointer;
}
.imgBox {
  width: 260px;
  height: 260px;
  border-radius: 20px;
  position: relative;
  left: 0;
  top: 0;
  img {
    width: 100%;
    height: 100%;
  }
  .Mask {
    background: black;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    justify-content: space-around;
    font-size: 30px;
  }
  .Mask:hover {
    opacity: 0.6;
  }
  cursor: pointer;
}
.footButtonS {
  display: flex;
  justify-content: space-between;
  padding: 0 150px;
  margin-top: 50px;
  .footButton {
    width: 180px;
    height: 70px;
    background: #ffdd00;
    color: black;
    // text-align: center;
    font-size: 25px;
    font-weight: bold;
    border-radius: 20px;
    cursor: pointer;
  }
  .footButton:active {
    background: black;
    color: white;
  }
}
.colBox {
  display: flex;
  margin-bottom: 20px;
  padding: 0 25px 0 0;
}
::v-deep .el-input__inner {
  color: white;
  font-size: 22px;
}
::v-deep .el-select__selected-item {
  color: white;
  font-size: 22px;
}
.imageBox {
  height: 800px;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>